package com.cxf.windex.entity;

import com.cxf.windex.base.util.DateUtil;
import com.cxf.windex.enums.OrderTypeEnum;
import com.cxf.windex.enums.ReviewEnum;
import io.swagger.annotations.ApiModelProperty;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Date;
import javax.persistence.*;
import lombok.Data;

@Data
@Table(name = "b_orders_task")
public class BOrdersTask {

    /**
     * 任务ID
     */
    @Id
    private Long id;

    /**
     * 订单ID
     */
    @ApiModelProperty(value = "订单ID")
    @Column(name = "order_id")
    private String orderId;

    /**
     * 资源ID
     */
    @ApiModelProperty(value = "资源ID")
    @Column(name = "resources_id")
    private Long resourcesId;

    @ApiModelProperty(value = "资源姓名")
    @Column(name = "resources_name")
    private String resourcesName;

    @ApiModelProperty(value = "资源手机号")
    @Column(name = "resources_phone")
    private String resourcesPhone;

    @ApiModelProperty(value = "资源微信openid")
    @Column(name = "resources_wxopenid")
    private String resourcesWxopenid;

    @ApiModelProperty(value = "商家openid")
    @Column(name = "shop_wxopenid")
    private String shopWxopenid;

    @ApiModelProperty(value = "商家姓名")
    @Column(name = "shop_name")
    private String shopName;

    @ApiModelProperty(value = "商家手机号")
    @Column(name = "shop_phone")
    private String shopPhone;

    /**
     * 订单标题
     */
    @ApiModelProperty(value = "订单标题")
    private String title;

    /**
     * 订单文件
     */
    @ApiModelProperty(value = "订单文件")
    private String file;

    /**
     * 类型 0海报 1语音
     */
    @ApiModelProperty(value = "类型 0海报 1语音")
    private String type;

    /**
     * 状态 0未开始 1进行中 2已完成 3已过期
     */
    @ApiModelProperty(value = "状态 0未开始 1进行中 2已完成  3已过期")
    private String status;

    @ApiModelProperty(value = "审核状态")
    @Column(name = "review_status")
    private String reviewStatus;

    /**
     * 创建时间
     */
    @Column(name = "crt_time")
    private Date crtTime;

    /**
     * 创建用户IP
     */
    @Column(name = "crt_host")
    private String crtHost;

    /**
     * 更新时间
     */
    @Column(name = "upd_time")
    private Date updTime;

    /**
     * 更新用户IP
     */
    @Column(name = "upd_host")
    private String updHost;

    /**
     * 开始时间
     */
    @ApiModelProperty(value = "开始时间")
    @Column(name = "b_time")
    private Date bTime;

    /**
     * 结束时间
     */
    @ApiModelProperty(value = "结束时间")
    @Column(name = "e_time")
    private Date eTime;

    @ApiModelProperty(value = "审核时间时间")
    @Column(name = "review_time")
    private Date reviewTime;

    @ApiModelProperty(value = "申诉时间")
    @Column(name = "appeal_time")
    private Date appealTime;

    @ApiModelProperty(value = "回执内容")
    @Column(name = "appeal")
    private String appeal;

    /**
     * 内容
     */
    @ApiModelProperty(value = "订单内容")
    private String content;

    @ApiModelProperty(value = "实际价格(村长)")
    @Column(name = "real_price")
    private BigDecimal realPrice;

    @ApiModelProperty(value = "支付价格")
    @Column(name = "pay_price")
    private BigDecimal payPrice;

    @ApiModelProperty(value = "凭证")
    @Column(name = "resources_files")
    private String resourcesFiles;

    @ApiModelProperty(value = "任务类型名称")
    @Transient
    private String typeName="海报";

    @ApiModelProperty(value = "状态名称")
    @Transient
    private String reviewStatusDesc;

    @Transient
    private String statusDesc;

    public void setType(String type){
        this.type=type;
        if("1".equals(type)){
            typeName="语音";
        }
    }
    public void setStatus(String status){
        this.status=status;
        statusDesc=OrderTypeEnum.getIdType(status).getDesc();
    }

    public void setReviewStatus(String reviewStatus){
        this.reviewStatus=reviewStatus;
        reviewStatusDesc=ReviewEnum.keyOf(reviewStatus).getDesc();
    }

    public  BOrdersTask initByOrders(BOrders orders,Long resourcesId,LocalDate localDate,BResouces bResouces,BShop bShop){
        this.title=orders.getTitle();
        this.content=orders.getContent();
        this.orderId=orders.getId();
        this.file=orders.getFile();
        this.type=orders.getType();
        this.status="0";
        this.resourcesId=resourcesId;
        this.bTime= DateUtil.getByLocalDate(localDate);
        this.eTime=DateUtil.getByLocalDate(localDate.plusDays(1));
        this.resourcesName=bResouces.getName();
        this.resourcesPhone=bResouces.getPhone();
        this.shopName=bShop.getName();
        this.shopPhone=bShop.getPhone();
        this.resourcesWxopenid=bResouces.getWxopenid();
        this.shopWxopenid=bShop.getWxopenid();
        switch (type){
            case "0":
                this.realPrice=bResouces.getLPrice();
                this.payPrice=bResouces.getPayLPrice();
                break;
            case "1":
                this.realPrice=bResouces.getVPrice();
                this.payPrice=bResouces.getPayVPrice();
                break;
            default:
                break;
        }


        return this;
    }

    public  BOrdersTask initAdminOrders(BOrders orders,Long resourcesId,LocalDate localDate,BResouces bResouces,BigDecimal price,BigDecimal realPrice){
        this.title=orders.getTitle();
        this.content=orders.getContent();
        this.orderId=orders.getId();
        this.file=orders.getFile();
        this.type=orders.getType();
        this.status="0";
        this.resourcesId=resourcesId;
        this.bTime= DateUtil.getByLocalDate(localDate);
        this.eTime=DateUtil.getByLocalDate(localDate.plusDays(1));
        this.resourcesName=bResouces.getName();
        this.resourcesPhone=bResouces.getPhone();
        this.resourcesWxopenid=bResouces.getWxopenid();

        this.realPrice=realPrice;
        this.payPrice=price;



        return this;
    }


}
